﻿using System;
using System.Diagnostics;
using HamcoWcs.Tools.Tibco.Entities;

namespace HamcoWcs.Tools.Tibco.MesMsgService
{
    public class MesMsgParser_WcsExcuted : IMesMsgParser
    {
        public EnumMesMsgStatus Status => EnumMesMsgStatus.WcsExcuted;

        public void HandleEvent(MesMsgQueue message, Context context)
        {
            try
            {
                if (string.IsNullOrEmpty(message.Return))
                {
                    context.Client.Insertable(new SystemErrorLog()
                    {
                        Log = $"TibcoTools->MesMsgParser->WcsExcuted:需要发送的报文内容为空，\r\n{message.Content}"
                    }).ExecuteCommand();
                }
                else
                {
                    context.TibcoTool.Send(message.Return, context.SendSubject);
                    message.Status = EnumMesMsgStatus.Completed;
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                message.Status = EnumMesMsgStatus.Error;
            }
        }
    }
}
